// delay for given number of microseconds (use 1-1000) or milliseconds (1-65535) using timer 3
// (C) Copyright 2009, 2010 Communications Programming, Inc.

#include "userLib.h"

extern UINT16 TimerTicksPerMicrosec;// for use in TMRx and other timer funcs eg delayTx

void delayT3_init()					// init timer for first use
{
	T3CON = T3CON_VAL; 				// timer on, set prescale
	PR3 = 0xFFFF;					// no reset
}

void delayT3_us( UINT16 us )		// delay a given number of microseconds
{									// use for us values < 1000 so that loop counter not blown
	us *= TimerTicksPerMicrosec;	// apply in param multiplier
	TMR3 = 0;						// reset timer value
	while( TMR3 < us )
		{}
}

void delayT3_ms( UINT16 ms )		// delay a given number of milliseconds (1-65535)
{
	while( ms-- )
		delayT3_us(1000);			// each millisec = 1000 microsecs
}

